// pages/blessingDetailed/blessingDetailed.js
const app = getApp()
const utils = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show:null,
    list:[],
    pageNumber:1,
    totalPages:null,
    blessWords:[],
  },
  morebtn(e){
    var that = this
    var index = e.currentTarget.dataset.index
    that.setData({
      blessWords:[]
    })
    // console.log('收起1', that.data.show,index)
    if(that.data.show==index){
      that.setData({
        show: null
      })
      // console.log('收起',that.data.show)
    } else {
      // console.log('展开', that.data.show)
      app.req({
        url: 'blessmini/rank/words',
        data: {
          type: e.currentTarget.dataset.type,
          actId: e.currentTarget.dataset.id
        },
        method: 'POST',
        success: function (res) {
          if (res.code == 200) {
              for (var i in res.data) {
                res.data[i].createTime = res.data[i].createTime.substring(11, 16)
              }
            that.setData({
              blessWords:res.data
            })
            console.log('列表', that.data.blessWords)
          }
        }
      })
      app.req({
        url: 'blessmini/blesscomment/allRead',
        data: {
          actType: e.currentTarget.dataset.acttype,
          actId: e.currentTarget.dataset.id
        },
        method: 'POST',
        success: function (res) {
          if (res.data == 200) {
            console.log('全读');
          }
        }
      })
      that.setData({
        show: index
      })
    }
  },
  getList(){
    var that = this
    app.req({
      url: "blessmini/rank/wordList",
      data: {
        pageNumber: that.data.pageNumber,
        pageSize: 10,
      },
      method: "post",
      success: function (res) {
        if (res.code == 200) {
          var rows = res.data.rows
          for(var item in rows){
            rows[item].createTime = rows[item].createTime.substring(0, 10)
          }
          that.setData({
            list:that.data.list.concat(res.data.rows),
            totalPages:res.data.totalPages,
          })
          console.log('祝福', that.data.list)
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      list:[],
      pageNumber:1,
    })
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if(that.data.totalPages > that.data.pageNumber){
      that.setData({
        pageNumber:that.data.pageNumber+1
      })
      that.getList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})